package com.example.learn_mybatis.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.learn_mybatis.pojo.Pager;
import com.example.learn_mybatis.pojo.Roles;
import com.example.learn_mybatis.mapper.RolesMapper;
import com.example.learn_mybatis.service.IRolesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chen
 * @since 2025-07-11
 */
@Service
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> implements IRolesService {

    @Override
    public Pager getAllRoles(Integer size, Integer p) {
        Pager pager = new Pager();

        Page<Roles> page = new Page<>(p, size);

        Page<Roles> rolePager = this.page(page);

        pager.setTotal(rolePager.getPages());
        pager.setList(Collections.singletonList(rolePager.getRecords()));
        return pager;
    }
}
